<?php
namespace Mouta\AmistateBundle\utils;

use Symfony\Bundle\FrameworkBundle\Routing\Router;

class Urls{
    protected $em;
    protected static $orden = array('18','1','19','2','3','4','5','6','7','8','9','10',
        '11','12','13','14','15','16','17','20','21','22','23','24','25','26','27','28','29','30',
        '31','32','33','34','35','36','37','38','39','40','41','42','43','190');

    public function  __construct(\Doctrine\ORM\EntityManager $em)
    {
        $this->em = $em;
        return $this->em;
    }

    /*public function getTagsUrl(){
        $usuarios = $this->em->getRepository('AmistateBundle:Tags')->findTags();
    }*/

    public function validateUrlList(array $tagsInUrl, $tagsDao){
        if( count($tagsDao)!=count($tagsInUrl) )
            return false;

        //ordeno los tagsDao como en la url
        $aux = array();
        foreach($tagsInUrl as $tu){
            foreach($tagsDao as $td){
                if($td->getTagGoogle() == $tu)
                    $aux[] = $td;
            }
        }

        $tagsOrdenados = Urls::getTagsOrdenados($aux);

        for($i=0; $i<3; $i++){
            if(isset($tagsInUrl[$i]))
            {
                if($tagsInUrl[$i] != $tagsOrdenados[$i]->getTagGoogle())
                    return false;
            }
        }

        return true;
    }

    public static function getTagsOrdenados($tags){
        $tagsOrdenados = array();
        foreach (self::$orden as $id_form){
            foreach($tags as $tag){
                if($tag->getIdForm() == $id_form)
                    $tagsOrdenados[] = $tag;
            }
        }
        return $tagsOrdenados;
    }
}